//
//  HomeTableViewController.swift
//  微博
//
//  Created by 段瑞金 on 16/5/11.
//  Copyright © 2016年 段瑞金. All rights reserved.
//

import UIKit

class HomeTableViewController: VisitorBaseTableViewController {

    //转场动画代理
    private let popAnimateDelegate = PopoverAnimateNSObject()
    override func viewDidLoad() {
        super.viewDidLoad()

        if !userLogin {
            visitorView.setUpVisitorViewInfo(nil, tipText: nil)
        }else{
            //设置导航条上的按钮
            setUpLoginBarButton()
        }

    }

}

//MARK:-设置登录之后的导航条上的按钮

extension HomeTableViewController {
    //添加按钮
    private func setUpLoginBarButton () {
           //下面的创建方式更接近系统 ,按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(imageName : "navigationbar_friendattention", action: #selector(HomeTableViewController.leftBarButtonClicked), target: self)
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(imageName : "navigationbar_pop", action: #selector(HomeTableViewController.rightBarButtonClicked), target: self)
        
        //标题按钮
        let titleButton = NavTitleButton()
        titleButton.setTitle("段瑞金微博", forState: .Normal)
        titleButton.titleLabel?.font = UIFont.systemFontOfSize(15)
        titleButton.setTitleColor(UIColor.blackColor(), forState: .Normal)
        titleButton.addTarget(self, action: #selector(HomeTableViewController.titleButtonClicked(_:)), forControlEvents: .TouchUpInside)
        titleButton.sizeToFit()
        navigationItem.titleView = titleButton
        
    }
    

    
    //MARK:-导航条按钮的点击
    @objc private func titleButtonClicked(titleButton : NavTitleButton) ->(){
        //设置按钮箭头的方向
        titleButton.selected = !titleButton.selected
        
        //创建菜单
        let popStoryBoard = UIStoryboard(name: "PopView", bundle: nil)
        let popVc = popStoryBoard.instantiateInitialViewController()!
        
        //自定义转场
        popVc.transitioningDelegate = popAnimateDelegate
        popVc.modalPresentationStyle = .Custom
        //弹出菜单
        presentViewController(popVc, animated: true, completion: nil)
        
        
    }
    //
    @objc private func leftBarButtonClicked() -> (){
        RJLOG("")
    }
    //扫描按钮
    @objc private func rightBarButtonClicked() -> (){
//        RJLOG("")
        let codeViewStoryboard = UIStoryboard(name: "QRCode", bundle: nil)
        let codeView = codeViewStoryboard.instantiateInitialViewController()!
        presentViewController(codeView, animated: true, completion: nil)
    }

}





